package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.system.common.enums.CardTypeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduAppointStudent.EduAppointStudentVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouseDetail.EduHouseDetailVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictQueryVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.*;
import com.jwsoft.manager.common.vo.eduStudentEnrollFamily.EduStudentEnrollFamilyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.StudentEnrollChooseSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentStatus.EduStudentStatusVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduStudentEnrollBeforeJhIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.integration.OperationCacheIntegration;
import com.jwsoft.manager.core.util.EduHelper;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 义务教育阶段预报名表业务实现类
 *
 * @author wangtao
 * @since 2022-12-13
 */
@ApiService(funcCode = "eduStudentEnrollBefore", title = "义务教育阶段预报名表")
@Slf4j
public class EduStudentEnrollBeforeJhIntegrationImpl implements EduStudentEnrollBeforeJhIntegration {
    @Autowired
    public EduStudentEnrollBeforeService eduStudentEnrollBeforeService;
    @Autowired
    EduHelper eduHelper;
    @Autowired
    OperationCacheIntegration operationCacheIntegration;
    @Autowired
    EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    EduSchoolVacancyService eduSchoolVacancyService;
    @Autowired
    private EduStudentEnrollFamilyService eduStudentEnrollFamilyService;
    @Autowired
    private EduSocialSecurityService eduSocialSecurityService;
    @Autowired
    private EduhSocialSecurityService eduhSocialSecurityService;
    @Autowired
    private EduCompanyService eduCompanyService;
    @Autowired
    private CommonIntegration commonIntegration;

    @Autowired
    private EduhCompanyService eduhCompanyService;
    @Autowired
    private EduSchoolService eduSchoolService;
    @Autowired
    private EduLivePlaceService eduLivePlaceService;
    @Autowired
    private EduhLivePlaceService eduhLivePlaceService;
    @Autowired
    private EduHouseService eduHouseService;

    @Autowired
    private EduhHouseService eduhHouseService;
    @Autowired
    private EduNetsignService eduNetsignService;

    @Autowired
    private EduhNetsignService eduhNetsignService;

    @Autowired
    private EduHouseholdService eduHouseholdService;

    @Autowired
    private EduhHouseholdService eduhHouseholdService;

    @Autowired
    private EduAppointStudentService eduAppointStudentService;

    @Autowired
    private EduPrivateAppointStudentService eduPrivateAppointStudentService;

    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    private EduStudentStatusService eduStudentStatusService;

    @Autowired
    private EduhStudentStatusService eduhStudentStatusService;

    @Autowired
    private EduAreaService eduAreaService;
    @Autowired
    private DictHelper dictHelper;
    @Autowired
    private EduFormSpecialService eduFormSpecialService;

    @Autowired
    private EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    private EduHouseDetailService eduHouseDetailService;

    @Autowired
    private EduhHouseDetailService eduhHouseDetailService;
    @Autowired
    private EduStudentEnrollImitateService eduStudentEnrollImitateService;
    @Autowired
    private EduAddressService eduAddressService;
    @Autowired
    private EduAddressSchoolService eduAddressSchoolService;

    @Autowired
    private  EduDataTaskDetailService eduDataTaskDetailService;

    @Autowired
    public EduhStudentEnrollPreService eduhStudentEnrollPreService;

    @Autowired
    private static final String STUDENT_ENROLL_PRE = "edu_student_enroll_pre";

    public static final String HOUSE_TABLE = "edu_house";
    public static final String HOUSE_TABLE_DETAIL = "edu_house_detail";
    public static final String HOUSEHOLD_TABLE = "edu_household";

    private static final String STUDENT_SOCIAL_SECURITY = "edu_social_security";
    private static final String EDU_NETSIGN = "edu_netsign";
    private static final String EDU_STUDENT_STATUS = "edu_student_status";
    private static final String EDU_COMPANY = "edu_company";
    private static final String EDU_LIVE_PLACE = "edu_live_place";

    @Override
    public PageInfo<EduStudentEnrollBeforeVO> queryBeforePageList(EduStudentEnrollBeforeQueryVO studentEnrollBeforeQueryVO) {
        if(studentEnrollBeforeQueryVO.getYear()==null){
            throw new AppException("查询年度不能为空");
        }
        // 开启分页
        if (studentEnrollBeforeQueryVO.getPageNum() == null || studentEnrollBeforeQueryVO.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            studentEnrollBeforeQueryVO.setPageNum(1);
            studentEnrollBeforeQueryVO.setPageSize(50);
        }

        //判断预采集表是否迁移
        List<EduStudentEnrollBeforeVO> list;
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), STUDENT_ENROLL_PRE));
        if (!queryHistoryFlag) {
            PageHelper.startPage(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
             list = eduStudentEnrollBeforeService.queryBeforeList(studentEnrollBeforeQueryVO);
            if (CollectionUtils.isEmpty(list)) {
                return PagerUtil.createEmptyPagerInfo(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            }
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(studentEnrollBeforeQueryVO.getYear(), STUDENT_ENROLL_PRE));
            if (encryptFlag) {
                //加密查询条件
                if (StringUtils.isNotBlank(studentEnrollBeforeQueryVO.getIdcard())){
                    studentEnrollBeforeQueryVO.setIdcard(CommonSecureUtil.sm4Encrypt(studentEnrollBeforeQueryVO.getIdcard()));
                }
                if (StringUtils.isNotBlank(studentEnrollBeforeQueryVO.getAllIdcard())){
                    studentEnrollBeforeQueryVO.setAllIdcard(CommonSecureUtil.sm4Encrypt(studentEnrollBeforeQueryVO.getAllIdcard()));
                }
            }
            PageHelper.startPage(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
             list = eduStudentEnrollBeforeService.queryBeforeListHistory(studentEnrollBeforeQueryVO);
            if (CollectionUtils.isEmpty(list)) {
                return PagerUtil.createEmptyPagerInfo(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            }
            //解密
            for (EduStudentEnrollBeforeVO eduStudentEnrollBeforeVO : list) {
                if ("1".equals(eduStudentEnrollBeforeVO.getEncryptFlag())){
                    if (StringUtils.isNotBlank(eduStudentEnrollBeforeVO.getIdcard())){
                        eduStudentEnrollBeforeVO.setIdcard(CommonSecureUtil.sm4Decrypt(eduStudentEnrollBeforeVO.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduStudentEnrollBeforeVO.getFullName())){
                        eduStudentEnrollBeforeVO.setFullName(CommonSecureUtil.sm4Decrypt(eduStudentEnrollBeforeVO.getFullName()));
                    }
                }
            }
        }

        PageInfo<EduStudentEnrollBeforeVO> pageInfo = new PageInfo<>(list);
        Integer year= studentEnrollBeforeQueryVO.getYear();
        long curTime = DateUtil.currentSeconds();
        String enrollStatus = EnrollStatusEnum.wait.getType();
        String enrollStatusName = EnrollStatusEnum.wait.getName();
        Map<String, Long> brochureMap = new HashMap<>();
        if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
            EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
            //判断义务段还是学前段
            String classify="2";
            queryVO.setClassify(classify);
            if(StringUtils.isBlank(studentEnrollBeforeQueryVO.getAreaCode())){
                queryVO.setAreaCode(eduHelper.thisAreaCode());
            }else {
                queryVO.setAreaCode(studentEnrollBeforeQueryVO.getAreaCode());
            }
            EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
            if(eduOperationCacheVO.getYear()>studentEnrollBeforeQueryVO.getYear()){
                enrollStatus=EnrollStatusEnum.finish.getType();
                enrollStatusName = EnrollStatusEnum.finish.getName();
            }else if(eduOperationCacheVO.getYear()-studentEnrollBeforeQueryVO.getYear()==0){
                Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
                EduOperationCacheDetailVO bmOp=operation.get("YW002");
                if(bmOp!=null&&bmOp.getBegTime()!=null&&bmOp.getEndTime()!=null){
                    long applyStart = bmOp.getBegTime().getTime() / 1000;
                    long applyEnd = bmOp.getEndTime().getTime() / 1000;
                    if (curTime >= applyStart && curTime <= applyEnd) {
                        enrollStatus = EnrollStatusEnum.on.getType();
                        enrollStatusName = EnrollStatusEnum.on.getName();
                    }else if (curTime > applyEnd) {
                        enrollStatus = EnrollStatusEnum.auth.getType();
                        enrollStatusName = EnrollStatusEnum.auth.getName();
                        //判断补报
                        EduOperationCacheDetailVO bBOp=operation.get("YW022");
                        if (bBOp!=null&&bBOp.getBegTime() != null && bBOp.getEndTime() != null) {
                            long applyStartTwo = bBOp.getBegTime().getTime() / 1000;
                            long applyEndTwo = bBOp.getEndTime().getTime() / 1000;
                            if (curTime >= applyStartTwo && curTime <= applyEndTwo) {
                                enrollStatus = EnrollStatusEnum.on.getType();
                                enrollStatusName = EnrollStatusEnum.on.getName();
                            } else if (curTime > applyEndTwo) {
                                EduOperationCacheDetailVO bbTwoOperation=operation.get("YW072");//第二批第二轮
                                if (bbTwoOperation!=null&&bbTwoOperation.getBegTime() != null && bbTwoOperation.getEndTime() != null) {
                                    long applyStartTwoTwo = bbTwoOperation.getBegTime().getTime() / 1000;
                                    long applyEndTwoTwo = bbTwoOperation.getEndTime().getTime() / 1000;
                                    if (curTime >= applyStartTwoTwo && curTime <= applyEndTwoTwo) {
                                        enrollStatus = EnrollStatusEnum.on.getType();
                                        enrollStatusName = EnrollStatusEnum.on.getName();
                                    } else if (curTime > applyEndTwoTwo) {
                                        //判断空额抢报
                                        EduOperationCacheDetailVO qBOp=operation.get("YW010");
                                        if (qBOp!=null&&qBOp.getBegTime() != null && qBOp.getEndTime() != null) {
                                            long spaceStart = qBOp.getBegTime().getTime() / 1000;
                                            long spaceEnd = qBOp.getEndTime().getTime() / 1000;
                                            if (curTime >= spaceStart && curTime <= spaceEnd) {
                                                enrollStatus = EnrollStatusEnum.onVacancy.getType();
                                                enrollStatusName = EnrollStatusEnum.onVacancy.getName();
                                            } else if (spaceEnd > applyEnd) {
                                                enrollStatus = EnrollStatusEnum.finish.getType();
                                                enrollStatusName = EnrollStatusEnum.finish.getName();
                                            }
                                        }
                                    }
                                }else{
                                    //判断空额抢报
                                    EduOperationCacheDetailVO qBOp=operation.get("YW010");
                                    if (qBOp!=null&&qBOp.getBegTime() != null && qBOp.getEndTime() != null) {
                                        long spaceStart = qBOp.getBegTime().getTime() / 1000;
                                        long spaceEnd = qBOp.getEndTime().getTime() / 1000;
                                        if (curTime >= spaceStart && curTime <= spaceEnd) {
                                            enrollStatus = EnrollStatusEnum.onVacancy.getType();
                                            enrollStatusName = EnrollStatusEnum.onVacancy.getName();
                                        } else if (spaceEnd > applyEnd) {
                                            enrollStatus = EnrollStatusEnum.finish.getType();
                                            enrollStatusName = EnrollStatusEnum.finish.getName();
                                        }
                                    }
                                }

                            }
                        }
                    }

                }
                //获取学校招生方案
                List<String> orgIdList =
                        list.stream().map(EduStudentEnrollBeforeVO::getSchoolId).distinct().collect(Collectors.toList());
                QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
                brochureQueryWrapper.lambda().in(EduEnrollmenBrochure::getSchoolId, orgIdList)
                        .eq(EduEnrollmenBrochure::getYear, year);
                List<EduEnrollmenBrochure> brochureList =
                        eduEnrollmenBrochureService.list(brochureQueryWrapper);
                if (!CollectionUtils.isEmpty(brochureList)) {
                    brochureMap = brochureList.stream().collect(Collectors.toMap(EduEnrollmenBrochure::getSchoolId, EduEnrollmenBrochure::getArticleId, (k1, k2) -> k1));
                }
            }


        }
        final String enrollStatusFinal = enrollStatus;
        final String enrollStatusNameFinal = enrollStatusName;

        List<EduStudentEnrollBeforeVO> pageList = pageInfo.getList();
        //转义数据字典值
        dictHelper.valueToName(pageList, Arrays.asList(SchoolDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getAreaCode, a -> a, (k1, k2) -> k1));
        // 获取学校空额名单
        Map<String, Integer> vacancyMap = new HashMap<>();
        if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
            List<String> schoolIdList = pageList.stream().map(EduStudentEnrollBeforeVO::getSchoolId).collect(Collectors.toList());
            QueryWrapper<EduSchoolVacancy> vacancyQueryWrapper = new QueryWrapper<>();
            vacancyQueryWrapper.lambda().select(EduSchoolVacancy::getSchoolId, EduSchoolVacancy::getVacancyNum)
                    .in(EduSchoolVacancy::getSchoolId, schoolIdList)
                    .eq(EduSchoolVacancy::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduSchoolVacancy::getYear, year);
            List<EduSchoolVacancy> vacancyList = eduSchoolVacancyService.list(vacancyQueryWrapper);

            if (!CollectionUtils.isEmpty(vacancyList)) {
                vacancyMap = vacancyList.stream().collect(Collectors.toMap(EduSchoolVacancy::getSchoolId, EduSchoolVacancy::getVacancyNum, (k1, k2) -> k1));
            }
        }
        //获取户籍信息
        List<String> houseIdList = new ArrayList<>();
        //获取房产信息
        List<String> householdIdList = new ArrayList<>();
        for (EduStudentEnrollBeforeVO studentEnrollBeforeVO : pageList) {
            if (StringUtils.isNotBlank(studentEnrollBeforeVO.getHouseId())) {
                if (!houseIdList.contains(studentEnrollBeforeVO.getHouseId())) {
                    houseIdList.add(studentEnrollBeforeVO.getHouseId());
                }
            }
            if (StringUtils.isNotBlank(studentEnrollBeforeVO.getHouseholdId())) {
                if (!householdIdList.contains(studentEnrollBeforeVO.getHouseholdId())) {
                    householdIdList.add(studentEnrollBeforeVO.getHouseholdId());
                }
            }
        }
        Map<String, EduHouse> houseMap = new HashMap<>();

        if (!CollectionUtils.isEmpty(houseIdList)) {
            List<EduHouse> houseList;
            //查询房产历史表
            Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), HOUSE_TABLE);
            if (!houseHistoryFlag) {
                QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                houseQueryWrapper.lambda().eq(EduHouse::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHouse::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduHouse::getHouseId, houseIdList);
                houseList = eduHouseService.list(houseQueryWrapper);
            } else {
                QueryWrapper<EduhHouse> eduhHouseQueryWrapper = new QueryWrapper<>();
                eduhHouseQueryWrapper.lambda().eq(EduhHouse::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduhHouse::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduhHouse::getHouseId, houseIdList);
                List<EduhHouse> eduhHouseList = eduhHouseService.list(eduhHouseQueryWrapper);
                houseList = Convert.toList(EduHouse.class, eduhHouseList);
            }
            if (!CollectionUtils.isEmpty(houseList)) {
                houseMap = houseList.stream().collect(Collectors.toMap(EduHouse::getHouseId, a -> a, (k1, k2) -> k1));
            }
        }

        Map<String, EduHousehold> householdMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(householdIdList)) {
            //查询户籍历史表
            List<EduHousehold> householdList;
            Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), HOUSEHOLD_TABLE);
            if (!houseHistoryFlag) {
                QueryWrapper<EduHousehold> houseQueryWrapper = new QueryWrapper<>();
                houseQueryWrapper.lambda().eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduHousehold::getHouseholdId, householdIdList);
                 householdList = eduHouseholdService.list(houseQueryWrapper);
            }else {
                QueryWrapper<EduhHousehold> eduhHouseQueryWrapper = new QueryWrapper<>();
                eduhHouseQueryWrapper.lambda().eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduhHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduhHousehold::getHouseholdId, householdIdList);
                List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(eduhHouseQueryWrapper);
                householdList = Convert.toList(EduHousehold.class,eduhHouseholdList);
            }
            if (!CollectionUtils.isEmpty(householdList)) {
                householdMap = householdList.stream().collect(Collectors.toMap(EduHousehold::getHouseholdId, a -> a, (k1, k2) -> k1));
            }
        }
        final Map<String, EduHouse> houseMapFinal = houseMap;
        final Map<String, EduHousehold> householdMapFinal = householdMap;
        final Map<String, Integer> vacancyMapFinal = vacancyMap;
        final Map<String, Long> brochureMapFinal = brochureMap;
        pageList.forEach(
                item -> {
                    //设置街道
                    if (!ObjectUtils.isEmpty(areaMap.get(item.getStreet()))) {
                        item.setStreetName(areaMap.get(item.getStreet()).getAreaName());
                    }
                    if (StringUtils.isNotBlank(item.getHouseId())) {
                        EduHouse eduHouse = houseMapFinal.get(item.getHouseId());
                        if (eduHouse != null) {
                            item.setRealPropertyDetails(eduHouse.getRealProperty());
                            item.setRegisterDate(eduHouse.getRegisterDate());
                        }
                    }
                    if (StringUtils.isNotBlank(item.getHouseholdId())) {
                        EduHousehold eduHousehold = householdMapFinal.get(item.getHouseholdId());
                        if (eduHousehold != null) {
                            if (StringUtils.isNotBlank(eduHousehold.getQysj())) {
                                try {
                                    item.setQysj(DateUtil.parse(eduHousehold.getQysj(), DatePattern.PURE_DATETIME_FORMAT));
                                } catch (Exception e) {
                                    try {
                                        item.setQysj(DateUtil.parse(eduHousehold.getQysj().substring(0, 8), DatePattern.PURE_DATE_FORMAT));
                                    } catch (Exception ex) {
                                        log.error("户籍启用时间转换异常");
                                    }
                                }

                            }
                            item.setAddressCity(eduHousehold.getAddressCity());
                            item.setAddressCountry(eduHousehold.getAddressCountry());
                            item.setAddressVillage(eduHousehold.getAddressVillage());
                        }
                    }

                    if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
                        //设置学校报名状态
                        if (item.getYear() > year) {
                            item.setEnrollStatus(EnrollStatusEnum.wait.getType());
                            item.setEnrollStatusName(EnrollStatusEnum.wait.getName());
                        } else if (item.getYear() < year) {
                            item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                            item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                        } else {
                            if (EnrollStatusEnum.onVacancy.getType().equals(enrollStatusFinal)) {
                                Integer num = vacancyMapFinal.get(item.getSchoolId());
                                if (num == null) {
                                    item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                    item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                                } else {
                                    if (num > 0) {
                                        item.setEnrollStatus(enrollStatusFinal);
                                        item.setEnrollStatusName(enrollStatusNameFinal);
                                        item.setVacancyNum(num);
                                    } else {
                                        item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                        item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                                    }
                                }
                            } else {
                                if (brochureMapFinal.containsKey(item.getSchoolId())) {
                                    item.setEnrollStatus(enrollStatusFinal);
                                    item.setEnrollStatusName(enrollStatusNameFinal);
                                } else {
                                    item.setEnrollStatus(EnrollStatusEnum.no.getType());
                                    item.setEnrollStatusName(EnrollStatusEnum.no.getName());
                                }

                            }
                        }
                    }
                });
        return PagerUtil.parsePagerVo(pageList, pageInfo);
    }
    @Override
    @OpApi(funcCode = "eduStudentEnrollBeforeJh0008", title = "预报名管理查询详情", funcType = FuncTypeEnum.query)
    @Cached(name = EduCache.EDU_CAN_ENROLL, key = "#vo.studentEnrollPreId", cacheType = CacheType.BOTH, expire = 3600, localExpire = 20)
    public EduStudentEnrollPreVO getPreDetail(EduStudentEnrollPreKeyVO vo) {
        if(vo.getYear()==null){
            vo.setYear(eduHelper.thisYear());
        }
        //有查询过历史数据
        EduStudentEnrollPreVO studentEnrollPreVO = getPreById(vo);
        //错误原因提交的时候有可能会影响后端关键字过滤器
        studentEnrollPreVO.setBeforeRemark("");
        studentEnrollPreVO.setHouseholdSyncRemark("");
        studentEnrollPreVO.setHouseSyncRemark("");
        studentEnrollPreVO.setCbSyncRemark("");
        studentEnrollPreVO.setQySyncRemark("");
        studentEnrollPreVO.setJzzSyncRemark("");
        studentEnrollPreVO.setNetsignSyncRemark("");
        studentEnrollPreVO.setFamilyRemark("");
        searchGuardians(studentEnrollPreVO);
        dictHelper.valueToName(studentEnrollPreVO, Arrays.asList(EduEnrollPreDictEnum.values()));
        if(StringUtils.isNotBlank(studentEnrollPreVO.getAreaCode())){
            studentEnrollPreVO.setAreaName(dictHelper.getAreaNameByCode(studentEnrollPreVO.getAreaCode()));
        }
        //获取招生年度
        int year=studentEnrollPreVO.getYear();
        //获取招生配置参数
        EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        String areaCode="";
        if (StringUtils.isNotBlank(vo.getAreaCode())){
            queryVO.setAreaCode(vo.getAreaCode());
            areaCode=vo.getAreaCode();
        }else {
            if (StringUtils.isNotBlank(studentEnrollPreVO.getAreaCode())) {
                queryVO.setAreaCode(studentEnrollPreVO.getAreaCode());
                areaCode=studentEnrollPreVO.getAreaCode();
            } else {
                queryVO.setAreaCode(eduHelper.thisAreaCode());
                areaCode=eduHelper.thisAreaCode();
            }
        }

        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
        if(eduOperationCacheVO==null){
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
        // 查询学校信息
        if (StringUtils.isNotBlank(studentEnrollPreVO.getSchoolId())) {
            EduSchoolVO school = eduSchoolService.getDetail(studentEnrollPreVO.getSchoolId());
            if (school != null) {
                studentEnrollPreVO.setSchoolName(school.getSchoolName());
            }
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getOrgId())) {
            EduSchoolVO school = eduSchoolService.getDetail(studentEnrollPreVO.getOrgId());
            if (school != null) {
                studentEnrollPreVO.setCjSchoolName(school.getSchoolName());
            }
        }

        //获取预报名信息
        EduStudentEnrollBeforeQueryVO beforeQueryVO = new EduStudentEnrollBeforeQueryVO();
        beforeQueryVO.setStudentEnrollPreId(studentEnrollPreVO.getStudentEnrollPreId());
        beforeQueryVO.setYear(studentEnrollPreVO.getYear());
        //有查询过历史数据
        PageInfo<EduStudentEnrollBeforeVO> beforeVOPageInfo = this.queryBeforePageList(beforeQueryVO);
        if (!CollectionUtils.isEmpty(beforeVOPageInfo.getList())) {
            for (EduStudentEnrollBeforeVO beforeVO : beforeVOPageInfo.getList()) {
                if (BoolEnum.TRUE.getType().equals(beforeVO.getSpecialFlag())){
                    QueryWrapper<EduFormSpecial> specialQueryWrapper = new QueryWrapper<>();
                    specialQueryWrapper.lambda().eq(EduFormSpecial::getSmallClassValue, beforeVO.getConfigName())
                           .eq(EduFormSpecial::getBigClassValue, beforeVO.getConfigTypeName())
                            .eq(EduFormSpecial::getYear, studentEnrollPreVO.getYear())
                            .eq(EduFormSpecial::getAreaCode, areaCode);
                    EduFormSpecial eduFormSpecial = eduFormSpecialService.getOne(specialQueryWrapper);
                    if (eduFormSpecial!= null) {
                        beforeVO.setSpecialFileFlag(eduFormSpecial.getFileFlag());
                    }
                }
            }
        }
        studentEnrollPreVO.setEnrollBeforeList(beforeVOPageInfo.getList());
        List<StudentEnrollChooseSchoolVO> chooseSchoolVOList=new ArrayList<>();
        if (!CollectionUtils.isEmpty(beforeVOPageInfo.getList())) {
            List<String> houseIdList = new ArrayList<>();
            for (EduStudentEnrollBeforeVO beforeVO : beforeVOPageInfo.getList()) {
                boolean chooseFlag=true;
                for(StudentEnrollChooseSchoolVO studentEnrollChooseSchoolVO:chooseSchoolVOList){
                    if(studentEnrollChooseSchoolVO.getSchoolId().equalsIgnoreCase(beforeVO.getSchoolId())){
                        chooseFlag=false;
                        break;
                    }
                }
                if(chooseFlag){
                    StudentEnrollChooseSchoolVO chooseSchoolVO=Convert.convert(StudentEnrollChooseSchoolVO.class,beforeVO);
                    chooseSchoolVOList.add(chooseSchoolVO);
                }
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(beforeVO.getSpecialFlag())) {
                    if (StringUtils.isNotBlank(beforeVO.getHouseId())) {
                        houseIdList.add(beforeVO.getHouseId());
                    }
                }
            }
            studentEnrollPreVO.setChooseSchoolList(chooseSchoolVOList);
            if (!CollectionUtils.isEmpty(houseIdList)) {
                //查询房产历史表
                List<EduHouse> eduHouseList;
                Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE);
                if (!houseHistoryFlag) {
                    QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                    houseQueryWrapper.lambda().in(EduHouse::getHouseId, houseIdList);
                    eduHouseList = eduHouseService.list(houseQueryWrapper);
                }else {
                    QueryWrapper<EduhHouse> eduhHouseQueryWrapper = new QueryWrapper<>();
                    eduhHouseQueryWrapper.lambda().in(EduhHouse::getHouseId, houseIdList);
                    List<EduhHouse> eduhHouses = eduhHouseService.list(eduhHouseQueryWrapper);
                    //解密
                    for (EduhHouse eduhHouse : eduhHouses) {
                        if ("1".equals(eduhHouse.getEncryptFlag())){
                            eduhHouseService.decrypt(eduhHouse);
                        }
                    }
                    eduHouseList = Convert.toList(EduHouse.class, eduhHouses);
                }
                List<EduHouseVO> houseTstdVOList = new ArrayList<>();
                //查询房产详情历史表
                List<EduHouseDetail> detailList;
                Boolean houseDetailHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE_DETAIL);
                if (!houseDetailHistoryFlag){
                    QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                    detailQueryWrapper.lambda()
                            .select(EduHouseDetail::getIdcard, EduHouseDetail::getFullName, EduHouseDetail::getHouseId, EduHouseDetail::getRealProperty, EduHouseDetail::getStatus)
                            .in(EduHouseDetail::getHouseId, houseIdList);
                    detailList = eduHouseDetailService.list(detailQueryWrapper);
                }else {
                    QueryWrapper<EduhHouseDetail> eduhHouseDetailQueryWrapper = new QueryWrapper<>();
                    eduhHouseDetailQueryWrapper.lambda()
                            .select(EduhHouseDetail::getIdcard, EduhHouseDetail::getFullName, EduhHouseDetail::getHouseId, EduhHouseDetail::getRealProperty, EduhHouseDetail::getStatus)
                            .in(EduhHouseDetail::getHouseId, houseIdList);
                    List<EduhHouseDetail> eduhHouseDetails = eduhHouseDetailService.list(eduhHouseDetailQueryWrapper);
                    //判断是否加密，解密
                    for (EduhHouseDetail eduhHouseDetail : eduhHouseDetails) {
                        if ("1".equals(eduhHouseDetail.getEncryptFlag())){
                            if (StringUtils.isNotBlank(eduhHouseDetail.getRealProperty())){
                                eduhHouseDetail.setRealProperty(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getRealProperty()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getObligee())){
                                eduhHouseDetail.setObligee(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getObligee()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getIdcard())){
                                eduhHouseDetail.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getIdcard()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getFullName())){
                                eduhHouseDetail.setFullName(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getFullName()));
                            }
                        }
                    }
                    detailList = Convert.toList(EduHouseDetail.class, eduhHouseDetails);
                }

                Map<String, List<EduHouseDetail>> detailMap = new HashMap<>();
                if (!CollectionUtils.isEmpty(detailList)) {
                    detailMap = detailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
                }
                for (EduHouse eduHouse : eduHouseList) {
                    EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);
                    houseVO.setRealPropertyDetails(eduHouse.getRealProperty());
                    List<EduHouseDetail> details = detailMap.get(eduHouse.getHouseId());
                    if (!CollectionUtils.isEmpty(details)) {
                        houseVO.setDetailList(Convert.toList(EduHouseDetailVO.class, details));
                        houseTstdVOList.add(houseVO);
                    }

                }
                studentEnrollPreVO.setHouseTstdList(houseTstdVOList);

            }
        }
        //获取户籍信息
        studentEnrollPreVO.setFmFlag(false);
        //查询户籍历史表
        List<EduHousehold> list;
        Boolean householdHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSEHOLD_TABLE);
        String idcard = studentEnrollPreVO.getIdcard();
        String idcardHistory = CommonSecureUtil.sm4Encrypt(studentEnrollPreVO.getIdcard());//加密后的身份证
        if (!householdHistoryFlag) {
            QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduHousehold::getIdcard, idcard)
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduHousehold::getQysj);
            list = eduHouseholdService.list(queryWrapper);
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), HOUSEHOLD_TABLE));
            QueryWrapper<EduhHousehold> queryWrapperHistory =  new QueryWrapper<>();
            queryWrapperHistory.lambda()
                    .eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduhHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduhHousehold::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduhHousehold::getQysj);
            //如果加密，使用加密的身份证
            if (encryptFlag) {
                queryWrapperHistory.lambda().eq(EduhHousehold::getIdcard, idcardHistory);
            }else{
                queryWrapperHistory.lambda().eq(EduhHousehold::getIdcard, idcard);
            }
            List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(queryWrapperHistory);
            for (EduhHousehold eduhHousehold : eduhHouseholdList) {
                if ("1".equals(eduhHousehold.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhHousehold.getIdcard())){
                        eduhHousehold.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getFullName())){
                        eduhHousehold.setFullName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getFullName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getBeforeName())){
                        eduhHousehold.setBeforeName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getBeforeName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getAddress())){
                        eduhHousehold.setAddress(CommonSecureUtil.sm4Decrypt(eduhHousehold.getAddress()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholdPlace())){
                        eduhHousehold.setHouseholdPlace(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholdPlace()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholder())){
                        eduhHousehold.setHouseholder(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholder()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholderIdcard())){
                        eduhHousehold.setHouseholderIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholderIdcard()));
                    }
                }
            }
            list = Convert.toList(EduHousehold.class, eduhHouseholdList);
        }

        if (!CollectionUtils.isEmpty(list)){
            EduHousehold household=list.get(0);
            EduHouseholdVO houseHoldVO = Convert.convert(EduHouseholdVO.class, household);
            studentEnrollPreVO.setHouseHoldVOAll(houseHoldVO);
            ArrayList<String> areaCodeList = new ArrayList<>();
            houseHoldVO.setTpSchoolMap(new HashMap<>());
            studentEnrollPreVO.setHouseholdSchoolVOList(getHouseholdSchool(studentEnrollPreVO,list,operation));
            if(!CollectionUtils.isEmpty(studentEnrollPreVO.getHouseholdSchoolVOList())){
                for(HouseholdSchoolVO householdSchoolVO:studentEnrollPreVO.getHouseholdSchoolVOList()){
                    if(householdSchoolVO.getCategoryFlag()&&!areaCodeList.contains(householdSchoolVO.getAreaCode())){
                        areaCodeList.add(householdSchoolVO.getAreaCode());
                    }
                    if (!CollectionUtils.isEmpty(householdSchoolVO.getToSchoolIdList())){
                        Map<String,List<String>> tpSchoolMap=new HashMap<>();
                        for (String tpSchoolId:householdSchoolVO.getToSchoolIdList()){
                            if(!tpSchoolMap.containsKey(tpSchoolId)){
                                List<String> tpAreaCodeList=new ArrayList<>();
                                tpAreaCodeList.add(householdSchoolVO.getAreaCode());
                                tpSchoolMap.put(tpSchoolId,tpAreaCodeList);
                            }else{
                                List<String> tpAreaCodeList=tpSchoolMap.get(tpSchoolId);
                                if(!tpAreaCodeList.contains(householdSchoolVO.getAreaCode())){
                                    tpAreaCodeList.add(householdSchoolVO.getAreaCode());
                                }
                                tpSchoolMap.put(tpSchoolId,tpAreaCodeList);
                            }
                        }
                        houseHoldVO.setTpSchoolMap(tpSchoolMap);

                    }

                }
            }

            if (StringUtils.isBlank(studentEnrollPreVO.getHouseholdPlace())) {
                studentEnrollPreVO.setHouseholdPlace(household.getAddress());
            }
            if(StringUtils.isNotBlank(household.getRelation())){
                List<String> znxxList=new ArrayList<>();
                znxxList.add("子");
                znxxList.add("女");
                znxxList.add("长子");
                znxxList.add("长女");
                znxxList.add("一子");
                znxxList.add("次子");
                znxxList.add("一女");
                znxxList.add("次女");
                znxxList.add("二子");
                znxxList.add("三子");
                znxxList.add("四子");
                znxxList.add("五子");
                znxxList.add("六子");
                znxxList.add("七子");
                znxxList.add("八子");
                znxxList.add("九子");
                znxxList.add("十子");
                znxxList.add("二女");
                znxxList.add("三女");
                znxxList.add("四女");
                znxxList.add("五女");
                znxxList.add("六女");
                znxxList.add("七女");
                znxxList.add("八女");
                znxxList.add("九女");
                znxxList.add("十女");
                znxxList.add("其他儿子");
                znxxList.add("其他女儿");
                znxxList.add("孩子");
                znxxList.add("独生子");
                znxxList.add("独生女");
                znxxList.add("养女或继女");
                znxxList.add("养子或继子");
                if (znxxList.contains(household.getRelation())){
                    studentEnrollPreVO.setFmFlag(true);
                }else{
                    studentEnrollPreVO.setFmFlag(false);
                }
            }else{
                studentEnrollPreVO.setFmFlag(false);
            }
            String addressId=household.getAddressId();
            if(!CollectionUtils.isEmpty(areaCodeList)){
                //学区已匹配到区域的，优先使用学区内的区域
                houseHoldVO.setAreaCodeList(areaCodeList);
                studentEnrollPreVO.setHouseHoldVO(houseHoldVO);
                studentEnrollPreVO.setHouseholdAddress(houseHoldVO.getAddress());
                studentEnrollPreVO.setAccountType(houseHoldVO.getAccountType());
                studentEnrollPreVO.setRelation(houseHoldVO.getRelation());
                List<String> sheetAreaCode=new ArrayList<>();
                if (StringUtils.isNotBlank(addressId)) {
                    QueryWrapper<EduAddress> addressQueryWrapper = new QueryWrapper<>();
                    addressQueryWrapper.lambda().select(EduAddress::getAddressId, EduAddress::getCityCode, EduAddress::getStreetCode).eq(EduAddress::getAddressId, addressId);
                    EduAddress addresses = eduAddressService.getOne(addressQueryWrapper, false);

                    if (addresses != null) {
                        if (StringUtil.isNotBlank(addresses.getStreetCode())) {
                            LambdaQueryWrapper<EduArea> areaLambdaQueryWrapper = new LambdaQueryWrapper<>();
                            areaLambdaQueryWrapper.select(EduArea::getParentId).eq(EduArea::getAreaCode, addresses.getStreetCode());
                            List<EduArea> eduAreaList = eduAreaService.list(areaLambdaQueryWrapper);
                            if (!CollectionUtils.isEmpty(eduAreaList)) {
                                sheetAreaCode.add(eduAreaList.get(0).getParentId());
                            }
                            if (addresses.getStreetCode().equalsIgnoreCase("330702005") || addresses.getStreetCode().equalsIgnoreCase("330702006")) {
                                //江南街道：33070200519:15三江街道：330702006 对婺城区开放
                                if (!sheetAreaCode.contains("330702")) {
                                    sheetAreaCode.add("330702");
                                }
                            }

                        } else {
                            if (StringUtil.isNotBlank(addresses.getCityCode())) {
                                //没有街道，按行政区划处理，婺城和开发互认
                                if (addresses.getCityCode().equalsIgnoreCase("330701")
                                        || addresses.getCityCode().equalsIgnoreCase("330703")) {
                                    sheetAreaCode.add(addresses.getCityCode());
                                } else if (addresses.getCityCode().equalsIgnoreCase("330702")) {
                                    sheetAreaCode.add(addresses.getCityCode());
                                    sheetAreaCode.add("330704");
                                } else if (addresses.getCityCode().equalsIgnoreCase("330704")) {
                                    sheetAreaCode.add(addresses.getCityCode());
                                    sheetAreaCode.add("330702");
                                }
                            }
                        }
                    } else {
                        if (StringUtil.isNotBlank(household.getAddress())) {
                            if (household.getAddress().indexOf("婺城区") >= 0) {
                                sheetAreaCode.add("330702");
                                sheetAreaCode.add("330704");
                            }
                            if (household.getAddress().indexOf("金东区") >= 0) {
                                sheetAreaCode.add("330703");
                            }
                            if (household.getAddress().indexOf("开发区") >= 0) {
                                sheetAreaCode.add("330702");
                                sheetAreaCode.add("330704");
                            }
                        }
                    }
                    if (!CollectionUtils.isEmpty(sheetAreaCode)) {
                        houseHoldVO.setSheetAreaCode(sheetAreaCode);
                    }
                }
            }else {
                //没有学区的，按地址匹配可选择的地市
                if (StringUtils.isNotBlank(addressId)) {
                    QueryWrapper<EduAddress> addressQueryWrapper = new QueryWrapper<>();
                    addressQueryWrapper.lambda().select(EduAddress::getAddressId, EduAddress::getCityCode, EduAddress::getStreetCode).eq(EduAddress::getAddressId, addressId);
                    EduAddress addresses = eduAddressService.getOne(addressQueryWrapper, false);

                    if (addresses != null) {
                        if (StringUtil.isNotBlank(addresses.getStreetCode())) {
                            LambdaQueryWrapper<EduArea> areaLambdaQueryWrapper = new LambdaQueryWrapper<>();
                            areaLambdaQueryWrapper.select(EduArea::getParentId).eq(EduArea::getAreaCode, addresses.getStreetCode());
                            List<EduArea> eduAreaList = eduAreaService.list(areaLambdaQueryWrapper);
                            if (!CollectionUtils.isEmpty(eduAreaList)) {
                                areaCodeList.add(eduAreaList.get(0).getParentId());
                            }
                            if (addresses.getStreetCode().equalsIgnoreCase("330702005") || addresses.getStreetCode().equalsIgnoreCase("330702006")) {
                                //江南街道：33070200519:15三江街道：330702006 对婺城区开放
                                if (!areaCodeList.contains("330702")) {
                                    areaCodeList.add("330702");
                                }
                            }

                        } else {
                            if (StringUtil.isNotBlank(addresses.getCityCode())) {
                                //没有街道，按行政区划处理，婺城和开发互认
                                if (addresses.getCityCode().equalsIgnoreCase("330701")
                                        || addresses.getCityCode().equalsIgnoreCase("330703")) {
                                    areaCodeList.add(addresses.getCityCode());
                                } else if (addresses.getCityCode().equalsIgnoreCase("330702")) {
                                    areaCodeList.add(addresses.getCityCode());
                                    areaCodeList.add("330704");
                                } else if (addresses.getCityCode().equalsIgnoreCase("330704")) {
                                    areaCodeList.add(addresses.getCityCode());
                                    areaCodeList.add("330702");
                                }
                            }
                        }
                    } else {
                        if (StringUtil.isNotBlank(household.getAddress())) {
                            if (household.getAddress().indexOf("婺城区") >= 0) {
                                areaCodeList.add("330702");
                                areaCodeList.add("330704");
                            }
                            if (household.getAddress().indexOf("金东区") >= 0) {
                                areaCodeList.add("330703");
                            }
                            if (household.getAddress().indexOf("开发区") >= 0) {
                                areaCodeList.add("330702");
                                areaCodeList.add("330704");
                            }
                        }
                    }
                    if (!CollectionUtils.isEmpty(areaCodeList)) {
                        houseHoldVO.setAreaCodeList(areaCodeList);
                        studentEnrollPreVO.setHouseHoldVO(houseHoldVO);
                        studentEnrollPreVO.setHouseholdAddress(houseHoldVO.getAddress());
                        studentEnrollPreVO.setAccountType(houseHoldVO.getAccountType());
                        studentEnrollPreVO.setRelation(houseHoldVO.getRelation());
                    }
                }
            }
        }
        //获取房产信息
        //获取本人以及父母名下房产信息

        List<String> idcardList = new ArrayList<>();//没有加密的身份证集合
        List<String> idcardSm4List =  new ArrayList<>();//加密身份证集合
        if (StringUtils.isNotBlank(studentEnrollPreVO.getIdcard())) {
            idcardList.add(studentEnrollPreVO.getIdcard());
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getFatherIdcard())) {
            idcardList.add(studentEnrollPreVO.getFatherIdcard());
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getMotherIdcard())) {
            idcardList.add(studentEnrollPreVO.getMotherIdcard());
        }
        if (!CollectionUtils.isEmpty(idcardList)) {
            // 身份证加密
            for (String idCard : idcardList) {
                idcardSm4List.add(CommonSecureUtil.sm4Encrypt(idCard));
            }
        }


        //查询房产历史表
        List<EduHouse> houseList;
        Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE);
        if (!houseHistoryFlag) {
             houseList = eduHouseService.getHouseByAllIdcard(idcardList, studentEnrollPreVO.getYear(), null, null);
        }else {
            // 迁移过后，判断是否加密
            List<EduhHouse> eduhHouseList;
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), HOUSE_TABLE));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                 eduhHouseList = eduHouseService.getHouseByAllIdcardHistory(idcardSm4List, studentEnrollPreVO.getYear(), null, null);
            }else {
                 eduhHouseList = eduHouseService.getHouseByAllIdcardHistory(idcardList, studentEnrollPreVO.getYear(), null, null);
            }
            //解密
            for (EduhHouse eduhHouse : eduhHouseList) {
                if ("1".equals(eduhHouse.getEncryptFlag())){
                    eduhHouseService.decrypt(eduhHouse);
                }
            }
            houseList = Convert.toList(EduHouse.class, eduhHouseList);
        }

        Boolean hasHouse=false;
        studentEnrollPreVO.setHasHouse(false);
        if (!CollectionUtils.isEmpty(houseList)) {
            List<EduHouseVO> houseVOList = new ArrayList<>();
            List<String> houseIdList = houseList.stream().map(EduHouse::getHouseId).collect(Collectors.toList());

            //查询房产详情历史表
            List<EduHouseDetail> detailList;
            Boolean houseDetailHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE_DETAIL);
            if (!houseDetailHistoryFlag){
                QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                detailQueryWrapper.lambda()
                        .select(EduHouseDetail::getIdcard, EduHouseDetail::getFullName, EduHouseDetail::getHouseId, EduHouseDetail::getRealProperty, EduHouseDetail::getStatus)
                        .in(EduHouseDetail::getHouseId, houseIdList);
                detailList = eduHouseDetailService.list(detailQueryWrapper);
            }else {
                QueryWrapper<EduhHouseDetail> eduhHouseDetailQueryWrapper = new QueryWrapper<>();
                eduhHouseDetailQueryWrapper.lambda()
                        .select(EduhHouseDetail::getIdcard, EduhHouseDetail::getFullName, EduhHouseDetail::getHouseId, EduhHouseDetail::getRealProperty, EduhHouseDetail::getStatus)
                        .in(EduhHouseDetail::getHouseId, houseIdList);
                List<EduhHouseDetail> eduhHouseDetails = eduhHouseDetailService.list(eduhHouseDetailQueryWrapper);
                //判断是否加密，解密
                for (EduhHouseDetail eduhHouseDetail : eduhHouseDetails) {
                    if ("1".equals(eduhHouseDetail.getEncryptFlag())){
                        if (StringUtils.isNotBlank(eduhHouseDetail.getRealProperty())){
                            eduhHouseDetail.setRealProperty(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getRealProperty()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getObligee())){
                            eduhHouseDetail.setObligee(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getObligee()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getIdcard())){
                            eduhHouseDetail.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getIdcard()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getFullName())){
                            eduhHouseDetail.setFullName(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getFullName()));
                        }
                    }
                }
                detailList = Convert.toList(EduHouseDetail.class, eduhHouseDetails);
            }

            Map<String,List<EduHouseDetail>> detailMap=new HashMap<>();
            if(!CollectionUtils.isEmpty(detailList)){
                detailMap=detailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
            }
            //设置房产学区
            studentEnrollPreVO.setHouseSchoolVOList(getHouseSchool(studentEnrollPreVO,houseList,operation));

            Map<String, List<HouseSchoolVO>> housGroupBy = new HashMap<>();
            if(!CollectionUtils.isEmpty(studentEnrollPreVO.getHouseSchoolVOList())){
                housGroupBy=studentEnrollPreVO.getHouseSchoolVOList().stream().collect(Collectors.groupingBy(HouseSchoolVO::getHouseId));
            }

            for (EduHouse eduHouse : houseList) {
                EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);
                houseVO.setRealPropertyDetails(eduHouse.getRealProperty());
                houseVO.setTpSchoolMap(new HashMap<>());
                List<EduHouseDetail> details=detailMap.get(eduHouse.getHouseId());
                if(!CollectionUtils.isEmpty(details)){
                    houseVO.setDetailList(Convert.toList(EduHouseDetailVO.class,details));
                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduHouse.getStatus())){
                        hasHouse=true;

                        ArrayList<String> areaCodeList = new ArrayList<>();

                        List<HouseSchoolVO> houseSchoolVOList=housGroupBy.get(eduHouse.getHouseId());
                        if(!CollectionUtils.isEmpty(houseSchoolVOList)){
                            for(HouseSchoolVO houseSchoolVO:houseSchoolVOList){
                                if(houseSchoolVO.getCategoryFlag()&&!areaCodeList.contains(houseSchoolVO.getAreaCode())){
                                    areaCodeList.add(houseSchoolVO.getAreaCode());
                                }
                                if (!CollectionUtils.isEmpty(houseSchoolVO.getToSchoolIdList())){
                                    Map<String,List<String>> tpSchoolMap=new HashMap<>();
                                    for (String tpSchoolId:houseSchoolVO.getToSchoolIdList()){
                                        if(!tpSchoolMap.containsKey(tpSchoolId)){
                                            List<String> tpAreaCodeList=new ArrayList<>();
                                            tpAreaCodeList.add(houseSchoolVO.getAreaCode());
                                            tpSchoolMap.put(tpSchoolId,tpAreaCodeList);
                                        }else{
                                            List<String> tpAreaCodeList=tpSchoolMap.get(tpSchoolId);
                                            if(!tpAreaCodeList.contains(houseSchoolVO.getAreaCode())){
                                                tpAreaCodeList.add(houseSchoolVO.getAreaCode());
                                            }
                                            tpSchoolMap.put(tpSchoolId,tpAreaCodeList);
                                        }
                                    }
                                    houseVO.setTpSchoolMap(tpSchoolMap);

                                }
                            }

                        }
                        if (!CollectionUtils.isEmpty(areaCodeList)) {
                            //有学区的，按学区的行政区划
                            houseVO.setAreaCodeList(areaCodeList);
                            if(StringUtils.isNotBlank(eduHouse.getAddressId())){
                                QueryWrapper<EduAddress> addressQueryWrapper=new QueryWrapper<>();
                                addressQueryWrapper.lambda().select(EduAddress::getAddressId,EduAddress::getCityCode,EduAddress::getStreetCode).eq(EduAddress::getAddressId,eduHouse.getAddressId());
                                List<EduAddress> addresseList = eduAddressService.list(addressQueryWrapper);
                                if(!CollectionUtils.isEmpty(addresseList)){
                                        if (StringUtils.isNotBlank(houseVO.getAddressId())) {

                                            //没有学区的按地址的行政区划
                                            List<String> sheetAreaList = new ArrayList<>();
                                            EduAddress addresses = null;
                                            for (EduAddress eduAddress : addresseList) {
                                                if (houseVO.getAddressId().equalsIgnoreCase(eduAddress.getAddressId())) {
                                                    addresses = eduAddress;
                                                    break;
                                                }
                                            }
                                            if (addresses != null) {
                                                if (StringUtil.isNotBlank(addresses.getStreetCode())) {
                                                    LambdaQueryWrapper<EduArea> areaLambdaQueryWrapper = new LambdaQueryWrapper<>();
                                                    areaLambdaQueryWrapper.select(EduArea::getParentId).eq(EduArea::getAreaCode, addresses.getStreetCode());
                                                    List<EduArea> eduAreaList = eduAreaService.list(areaLambdaQueryWrapper);
                                                    if (!CollectionUtils.isEmpty(eduAreaList)) {
                                                        sheetAreaList.add(eduAreaList.get(0).getParentId());
                                                    }
                                                    if (addresses.getStreetCode().equalsIgnoreCase("330702005") || addresses.getStreetCode().equalsIgnoreCase("330702006")) {
                                                        //江南街道：33070200519:15三江街道：330702006 对婺城区开放
                                                        if (!sheetAreaList.contains("330702")) {
                                                            sheetAreaList.add("330702");
                                                        }
                                                    }

                                                } else {
                                                    if (StringUtil.isNotBlank(addresses.getCityCode())) {
                                                        //没有街道，按行政区划处理，婺城和开发互认
                                                        if (addresses.getCityCode().equalsIgnoreCase("330701")
                                                                || addresses.getCityCode().equalsIgnoreCase("330703")) {
                                                            sheetAreaList.add(addresses.getCityCode());
                                                        } else if (addresses.getCityCode().equalsIgnoreCase("330702")) {
                                                            sheetAreaList.add(addresses.getCityCode());
                                                            sheetAreaList.add("330704");
                                                        } else if (addresses.getCityCode().equalsIgnoreCase("330704")) {
                                                            sheetAreaList.add(addresses.getCityCode());
                                                            sheetAreaList.add("330702");
                                                        }
                                                    }
                                                }
                                            } else {
                                                if (StringUtil.isNotBlank(houseVO.getAddress())) {
                                                    if (houseVO.getAddress().indexOf("婺城区") >= 0) {
                                                        sheetAreaList.add("330702");
                                                        sheetAreaList.add("330704");
                                                    }
                                                    if (houseVO.getAddress().indexOf("金东区") >= 0) {
                                                        sheetAreaList.add("330703");
                                                    }
                                                    if (houseVO.getAddress().indexOf("开发区") >= 0) {
                                                        sheetAreaList.add("330702");
                                                        sheetAreaList.add("330704");
                                                    }
                                                }

                                            }
                                            if(!CollectionUtils.isEmpty(sheetAreaList)){
                                                houseVO.setSheetAreaCode(sheetAreaList);
                                            }else{
                                                //地址未解析出来的，按全市都可以报名处理
                                                sheetAreaList.add("330702");
                                                sheetAreaList.add("330704");
                                                sheetAreaList.add("330701");
                                                sheetAreaList.add("330703");
                                                houseVO.setSheetAreaCode(sheetAreaList);
                                            }

                                        }else{
                                            List<String> sheetAreaList = new ArrayList<>();
                                            //地址未解析出来的，按全市都可以报名处理
                                            sheetAreaList.add("330702");
                                            sheetAreaList.add("330704");
                                            sheetAreaList.add("330701");
                                            sheetAreaList.add("330703");
                                            houseVO.setSheetAreaCode(sheetAreaList);
                                        }


                                }else{
                                    List<String> sheetAreaList = new ArrayList<>();
                                    //地址未解析出来的，按全市都可以报名处理
                                    sheetAreaList.add("330702");
                                    sheetAreaList.add("330704");
                                    sheetAreaList.add("330701");
                                    sheetAreaList.add("330703");
                                    houseVO.setSheetAreaCode(sheetAreaList);
                                }

                            }else{
                                List<String> sheetAreaList = new ArrayList<>();
                                //地址未解析出来的，按全市都可以报名处理
                                sheetAreaList.add("330702");
                                sheetAreaList.add("330704");
                                sheetAreaList.add("330701");
                                sheetAreaList.add("330703");
                                houseVO.setSheetAreaCode(sheetAreaList);
                            }
                        }
                    }
                    houseVOList.add(houseVO);
                }

            }

            studentEnrollPreVO.setHasHouse(hasHouse);
            studentEnrollPreVO.setHouseList(houseVOList);

        }
        //获取参保信息
        List<String> areaList=new ArrayList<>(0);
        areaList.add("330700");
        areaList.add("330799");
        areaList.add("330701");
        areaList.add("330702");
        areaList.add("330703");
        areaList.add("330704");
        List<String> aae140List=new ArrayList<>();
        aae140List.add("110");
        aae140List.add("120");
        //判断是否迁移
        List<EduSocialSecurity> socialSecurityList;
        boolean socialHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_SOCIAL_SECURITY);
        // 根据是否查询历史表，调用不同方法
        if (!socialHistoryFlag) {
            QueryWrapper<EduSocialSecurity> securityQueryWrapper = new QueryWrapper<>();
            securityQueryWrapper.lambda().eq(EduSocialSecurity::getYear, studentEnrollPreVO.getYear())
                    .in(EduSocialSecurity::getAab301, areaList)
                    .in(EduSocialSecurity::getAae140, aae140List)
                    .in(EduSocialSecurity::getAac002, idcardList)
                    .orderByAsc(EduSocialSecurity::getAac147).orderByAsc(EduSocialSecurity::getAae140).orderByAsc(EduSocialSecurity::getAae030);
            socialSecurityList= eduSocialSecurityService.list(securityQueryWrapper);
        }else {
            QueryWrapper<EduhSocialSecurity> eduhSecurityQueryWrapper = new QueryWrapper<>();
            eduhSecurityQueryWrapper.lambda().eq(EduhSocialSecurity::getYear, studentEnrollPreVO.getYear())
                    .in(EduhSocialSecurity::getAab301, areaList)
                    .in(EduhSocialSecurity::getAae140, aae140List)
                    .in(EduhSocialSecurity::getAac002, idcardList)
                    .orderByAsc(EduhSocialSecurity::getAac147).orderByAsc(EduhSocialSecurity::getAae140).orderByAsc(EduhSocialSecurity::getAae030);
            // // 迁移过后，判断是否加密
            // Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_SOCIAL_SECURITY));
            // //如果加密，把查询条件加密
            // if (encryptFlag) {
            //     eduhSecurityQueryWrapper.lambda().in(EduhSocialSecurity::getAac002,idcardSm4List );
            // }else {
            //     eduhSecurityQueryWrapper.lambda().in(EduhSocialSecurity::getAac002, idcardList);
            // }
            List<EduhSocialSecurity> eduhSocialSecurityList = eduhSocialSecurityService.list(eduhSecurityQueryWrapper);
            for (EduhSocialSecurity eduhSocialSecurity : eduhSocialSecurityList) {
                if ("1".equals(eduhSocialSecurity.getEncryptFlag())){
                    if (StringUtils.isNotBlank(eduhSocialSecurity.getAac003())) {
                        eduhSocialSecurity.setAac003(CommonSecureUtil.sm4Decrypt(eduhSocialSecurity.getAac003()));
                    }
                    if (StringUtils.isNotBlank(eduhSocialSecurity.getAac147())) {
                        eduhSocialSecurity.setAac147(CommonSecureUtil.sm4Decrypt(eduhSocialSecurity.getAac147()));
                    }
                }
            }
            socialSecurityList = Convert.toList(EduSocialSecurity.class, eduhSocialSecurityList);
        }
        if (!CollectionUtils.isEmpty(socialSecurityList)) {
            List<EduSocialSecurityVO> cbVOList = Convert.toList(EduSocialSecurityVO.class, socialSecurityList);
            for(EduSocialSecurityVO eduSocialSecurityVO:cbVOList){
                eduSocialSecurityVO.setAae140Name(dictHelper.getValue("AAE140",eduSocialSecurityVO.getAae140()));
                eduSocialSecurityVO.setAab301Name(dictHelper.getValue("AREA",eduSocialSecurityVO.getAab301()));
                if("1".equalsIgnoreCase(eduSocialSecurityVO.getAac008())){
                    if("1".equalsIgnoreCase(eduSocialSecurityVO.getAac031())){
                        eduSocialSecurityVO.setStatus("1");
                        eduSocialSecurityVO.setStatusName("正常参保");
                    }else{
                        eduSocialSecurityVO.setStatus("2");
                        eduSocialSecurityVO.setStatusName("参保中断");
                    }
                }else{
                    eduSocialSecurityVO.setStatus("3");
                    eduSocialSecurityVO.setStatusName("参保终止");
                }
            }
            studentEnrollPreVO.setCbList(cbVOList);
        }
        //获取网签信息
        //根据任务判断是否当前年度处理过迁移数据
        List<EduNetsign> netsignList;
        Boolean netsignHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), EDU_NETSIGN);
        if (!netsignHistoryFlag) {
            QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
            netsignQueryWrapper.lambda().eq(EduNetsign::getYear, studentEnrollPreVO.getYear())
                    .in(EduNetsign::getIdcard, idcardList).orderByDesc(EduNetsign::getStatus).orderByAsc(EduNetsign::getBasj);
            netsignList = eduNetsignService.list(netsignQueryWrapper);
        }else {
            QueryWrapper<EduhNetsign> eduhNetsignQueryWrapper = new QueryWrapper<>();
            eduhNetsignQueryWrapper.lambda()
                    .eq(EduhNetsign::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduhNetsign::getStatus)
                    .orderByAsc(EduhNetsign::getBasj);
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_NETSIGN));
            if (encryptFlag) {
                eduhNetsignQueryWrapper.lambda().in(EduhNetsign::getIdcard,idcardSm4List );
            }else {
                eduhNetsignQueryWrapper.lambda().in(EduhNetsign::getIdcard, idcardList);
            }
            List<EduhNetsign> EduhNetsign = eduhNetsignService.list(eduhNetsignQueryWrapper);
            for (EduhNetsign eduhNetsign : EduhNetsign) {
                if ("1".equals(eduhNetsign.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhNetsign.getIdcard())){
                        eduhNetsign.setIdcard(CommonSecureUtil.sm4Decrypt(eduhNetsign.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhNetsign.getXm())){
                        eduhNetsign.setXm(CommonSecureUtil.sm4Decrypt(eduhNetsign.getXm()));
                    }
                    if (StringUtils.isNotBlank(eduhNetsign.getDz())){
                        eduhNetsign.setDz(CommonSecureUtil.sm4Decrypt(eduhNetsign.getDz()));
                    }
                }
            }
            netsignList = Convert.toList(EduNetsign.class, EduhNetsign);
        }
        if (!CollectionUtils.isEmpty(netsignList)) {
            List<EduNetsignVO> netsignVOList = Convert.toList(EduNetsignVO.class, netsignList);
            for (EduNetsignVO eduNetsignVO : netsignVOList) {
                if (StringUtils.isNotBlank(eduNetsignVO.getSchoolId())) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(eduNetsignVO.getSchoolId());
                    if (eduSchool != null) {
                        eduNetsignVO.setSchoolName(eduSchool.getSchoolName());
                    }

                }
            }
            studentEnrollPreVO.setWqList(netsignVOList);
        }
        //获取学籍信息
        //根据任务判断是否当前年度处理过迁移数据
        EduStudentStatus eduStudentStatus;
        Boolean statusHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_STUDENT_STATUS);
        if (!statusHistoryFlag) {
            QueryWrapper<EduStudentStatus> statusQueryWrapper = new QueryWrapper<>();
            statusQueryWrapper.lambda().eq(EduStudentStatus::getYear, studentEnrollPreVO.getYear())
                    .eq(EduStudentStatus::getIdcard, idcard);
            eduStudentStatus = eduStudentStatusService.getOne(statusQueryWrapper, false);
        }else {
            QueryWrapper<EduhStudentStatus> eduhStatusQueryWrapper = new QueryWrapper<>();
            eduhStatusQueryWrapper.lambda()
                    .eq(EduhStudentStatus::getYear, studentEnrollPreVO.getYear());
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_STUDENT_STATUS));
            if (encryptFlag) {
                eduhStatusQueryWrapper.lambda().eq(EduhStudentStatus::getIdcard,idcardHistory );
            }else {
                eduhStatusQueryWrapper.lambda().eq(EduhStudentStatus::getIdcard, idcard);
            }
            EduhStudentStatus eduhStudentStatus = eduhStudentStatusService.getOne(eduhStatusQueryWrapper, false);
            if (eduhStudentStatus != null) {
                if ("1".equals(eduhStudentStatus.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhStudentStatus.getIdcard())) {
                        eduhStudentStatus.setIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFullName())) {
                        eduhStudentStatus.setFullName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFullName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFatherIdcard())) {
                        eduhStudentStatus.setFatherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFatherIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFatherName())) {
                        eduhStudentStatus.setFatherName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFatherName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getMotherName())) {
                        eduhStudentStatus.setMotherName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getMotherName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getMotherIdcard())) {
                        eduhStudentStatus.setMotherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getMotherIdcard()));
                    }
                }
            }
            eduStudentStatus = Convert.convert(EduStudentStatus.class, eduhStudentStatus);
        }

        if (eduStudentStatus != null) {
            EduStudentStatusVO studentStatusVO = Convert.convert(EduStudentStatusVO.class, eduStudentStatus);
            if (StringUtils.isNotBlank(studentStatusVO.getSchoolId())) {
                EduSchoolVO eduSchool = eduSchoolService.getDetail(studentStatusVO.getSchoolId());
                if (eduSchool != null) {
                    studentStatusVO.setSchoolName(eduSchool.getSchoolName());
                }

            }
            studentEnrollPreVO.setStudentStatusVO(studentStatusVO);
        }
        //获取城区E
        QueryWrapper<EduAppointStudent> appointStudentQueryWrapper = new QueryWrapper<>();
        appointStudentQueryWrapper.lambda().eq(EduAppointStudent::getYear, studentEnrollPreVO.getYear())
                .eq(EduAppointStudent::getStatus, BoolEnum.TRUE.getType())
                .eq(EduAppointStudent::getIdcard, idcard);
        List<EduAppointStudent> eduAppointStudentList = eduAppointStudentService.list(appointStudentQueryWrapper);
        if (!CollectionUtils.isEmpty(eduAppointStudentList)) {
            List<EduAppointStudentVO> cqeList = new ArrayList<>();
            for (EduAppointStudent eduAppointStudent : eduAppointStudentList) {
                EduAppointStudentVO eduAppointStudentVO = Convert.convert(EduAppointStudentVO.class, eduAppointStudent);
                if (StringUtils.isNotBlank(eduAppointStudentVO.getSchoolId())) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(eduAppointStudentVO.getSchoolId());
                    if (eduSchool != null) {
                        BeanUtil.copyProperties(eduSchool, eduAppointStudentVO);
                    }

                }
                cqeList.add(eduAppointStudentVO);
            }
            studentEnrollPreVO.setAppointFlag(BoolEnum.TRUE.getType());
            studentEnrollPreVO.setCqeList(cqeList);
        } else {
            studentEnrollPreVO.setAppointFlag(BoolEnum.FALSE.getType());
        }
        //获取直升班
        QueryWrapper<EduPrivateAppointStudent> privateAppointStudentQueryWrapper = new QueryWrapper<>();
        privateAppointStudentQueryWrapper.lambda().eq(EduPrivateAppointStudent::getYear, studentEnrollPreVO.getYear())
                .eq(EduPrivateAppointStudent::getStatus, BoolEnum.TRUE.getType())
                .eq(EduPrivateAppointStudent::getIdcard, idcard);
        EduPrivateAppointStudent eduPrivateAppointStudent = eduPrivateAppointStudentService.getOne(privateAppointStudentQueryWrapper, false);
        if (eduPrivateAppointStudent != null) {
            EduPrivateAppointStudentVO promotionPreVO = Convert.convert(EduPrivateAppointStudentVO.class, eduPrivateAppointStudent);
            if (StringUtils.isNotBlank(promotionPreVO.getSchoolId())) {
                EduSchoolVO eduSchool = eduSchoolService.getDetail(promotionPreVO.getSchoolId());
                if (eduSchool != null) {
                    BeanUtil.copyProperties(eduSchool, promotionPreVO);
                }
            }
            studentEnrollPreVO.setPrivateAppointFlag(BoolEnum.TRUE.getType());
            studentEnrollPreVO.setZsbVO(promotionPreVO);
        } else {
            studentEnrollPreVO.setPrivateAppointFlag(BoolEnum.FALSE.getType());
        }
        //开办企业
        //根据任务判断是否当前年度处理过迁移数据
        List<EduCompany> companyList;
        Boolean companyHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_COMPANY);
        if (!companyHistoryFlag) {
            QueryWrapper<EduCompany> companyQueryWrapper = new QueryWrapper<>();
            companyQueryWrapper.lambda().eq(EduCompany::getYear, studentEnrollPreVO.getYear())
                    .in(EduCompany::getFrZjhm, idcardList);
            companyList = eduCompanyService.list(companyQueryWrapper);
        }else{
            QueryWrapper<EduhCompany> eduhCompanyQueryWrapper = new QueryWrapper<>();
            eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getYear, studentEnrollPreVO.getYear());
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_COMPANY));
            if (encryptFlag) {
                eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getFrZjhm,idcardHistory );
            }else {
                eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getFrZjhm, idcard);
            }
            List<EduhCompany> eduhCompanyList = eduhCompanyService.list(eduhCompanyQueryWrapper);
            for (EduhCompany eduCompanyVO : eduhCompanyList) {
                if ("1".equals(eduCompanyVO.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduCompanyVO.getTyxydm())) {
                        eduCompanyVO.setTyxydm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getTyxydm()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getDh())) {
                        eduCompanyVO.setDh(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getDh()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrmc())) {
                        eduCompanyVO.setFrmc(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrmc()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrZjhm())) {
                        eduCompanyVO.setFrZjhm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrZjhm()));
                    }
                }
            }
            companyList = Convert.toList(EduCompany.class, eduhCompanyList);
        }
        if (!CollectionUtils.isEmpty(companyList)) {
            List<EduCompanyVO> qyVOList = Convert.toList(EduCompanyVO.class, companyList);
            studentEnrollPreVO.setQyList(qyVOList);
        }
        //居住证信息
        List<EduLivePlace> livePlaceList;
        Boolean placeHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_LIVE_PLACE);
        if (!placeHistoryFlag) {
            QueryWrapper<EduLivePlace> livePlaceQueryWrapper = new QueryWrapper<>();
            livePlaceQueryWrapper.lambda().eq(EduLivePlace::getYear, studentEnrollPreVO.getYear())
                    .in(EduLivePlace::getAreaCode, areaList)
                    .in(EduLivePlace::getSfzh, idcardList).orderByAsc(EduLivePlace::getSfzh);
             livePlaceList = eduLivePlaceService.list(livePlaceQueryWrapper);
        }else {
            QueryWrapper<EduhLivePlace> eduhLivePlaceQueryWrapper = new QueryWrapper<>();
            eduhLivePlaceQueryWrapper.lambda().eq(EduhLivePlace::getYear, studentEnrollPreVO.getYear())
                    .in(EduhLivePlace::getAreaCode, areaList);
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_LIVE_PLACE));
            if (encryptFlag) {
                eduhLivePlaceQueryWrapper.lambda().in(EduhLivePlace::getSfzh, idcardHistory);
            }else {
                eduhLivePlaceQueryWrapper.lambda().in(EduhLivePlace::getSfzh, idcardList);
            }
            List<EduhLivePlace> eduhLivePlaceList = eduhLivePlaceService.list(eduhLivePlaceQueryWrapper);
            for (EduhLivePlace EduhLivePlace : eduhLivePlaceList) {
                //对字段进行解密
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(EduhLivePlace.getEncryptFlag())){
                    eduhLivePlaceService.decrypt(EduhLivePlace);
                }
            }
            livePlaceList = Convert.toList(EduLivePlace.class, eduhLivePlaceList);
        }
        if (!CollectionUtils.isEmpty(livePlaceList)) {
            List<EduLivePlaceVO> livePlaceVOList = Convert.toList(EduLivePlaceVO.class, livePlaceList);
            studentEnrollPreVO.setJzzList(livePlaceVOList);
        }
        studentEnrollPreVO.setBmFlag(checkEnroll(studentEnrollPreVO.getIdcard(),studentEnrollPreVO.getYear()));
        studentEnrollPreVO.setMnEnrollFlag(checkMnEnroll(studentEnrollPreVO.getIdcard(),studentEnrollPreVO.getYear()));

        return studentEnrollPreVO;
    }
    //获取房产信息所属学校
    public List<HouseSchoolVO> getHouseSchool(EduStudentEnrollPreVO eduStudentEnrollPre,List<EduHouse> list, Map<String, EduOperationCacheDetailVO> operation){
        List<HouseSchoolVO> retList=new ArrayList<>();

        if (!CollectionUtils.isEmpty(list)){
            CommonVO tpVO = new CommonVO();
            tpVO.setParamKey("EDU_MZGXDXQ_TP");
            String schoolTPStr = commonIntegration.getValueByKey(tpVO);
            List<BreakAreaVO> tpschoolList=new ArrayList<>();
            if (StringUtils.isNotBlank(schoolTPStr)){
                tpschoolList= JSON.parseArray(schoolTPStr, BreakAreaVO.class);
            }
            // 正学区房产启用是参数
            EduOperationCacheDetailVO fcOperation=operation.get("YW024");
            Long houseEndTime=fcOperation.getEndTime().getTime()/1000;
            // 服务区房产启用是参数
            EduOperationCacheDetailVO fcfwOperation=operation.get("YW060");
            if (fcfwOperation.getEndTime() == null){
                throw new AppException("YW060服务区房产启用时间不能为空");
            }
            Long houseEndTimeFw=fcfwOperation.getEndTime().getTime()/1000;
            for(EduHouse eduHouse:list){
                if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduHouse.getStatus())){
                    continue;
                }
                if(!BoolEnum.TRUE.getType().equals(eduHouse.getUseQueryFlag())){
                    //3年锁定未比对的,房产不算
                    continue;
                }
                if(BoolEnum.TRUE.getType().equals(eduHouse.getUseFlag())){
                    //3年内房产使用，不能就读
                    continue;
                }
                //获取房产地址关联的学校信息
                Boolean flag = true;
                String addressId=eduHouse.getAddressId();
                String address= Convert.toDBC(eduHouse.getAddress());
                if(StringUtils.isNotBlank(eduHouse.getAddressId())) {
                    EduAddress eduAddress = eduAddressService.getById(addressId);
                    if (eduAddress == null) {
                        flag = true;
                        addressId = "";
                    } else {
                        if (!eduAddress.getAddressName().equals(address)) {
                            flag = true;
                            addressId = "";
                        } else {
                            flag = false;

                        }
                    }
                }
                if (flag) {
                    QueryWrapper<EduAddress> eduAddressQueryWrapper = new QueryWrapper<>();
                    eduAddressQueryWrapper.lambda().eq(EduAddress::getAddressName, address);
                    List<EduAddress> addressList = eduAddressService.list(eduAddressQueryWrapper);
                    if (CollectionUtils.isEmpty(addressList)) {
                        throw new AppException("地址池中未找到该房产地址，请先联系管理员添加");
                    } else {
                        if (addressList.size() > 1) {
                            throw new AppException("同一房产地址在地址池中找到多条数据，请联系管理员处理");
                        }
                        addressId = addressList.get(0).getAddressId();
                    }
                }

                SchoolDistrictQueryVO queryVO=new SchoolDistrictQueryVO();
                //剔除学段，查询地址相关所有学校
                if (CollectionUtils.isEmpty(tpschoolList)) {
                    queryVO.setSchoolCategory(eduStudentEnrollPre.getSchoolCategory());
                }
                queryVO.setAddressId(addressId);
                List<SchoolDistrictVO> schoolList= eduAddressSchoolService.getSchoolInfo(queryVO);
                if (!CollectionUtils.isEmpty(schoolList)){
                    for(SchoolDistrictVO eduAddressSchool:schoolList){
                        boolean conFlag = false;
                        for (HouseSchoolVO houseSchoolVO : retList) {
                            if (eduAddressSchool.getAddressId().equalsIgnoreCase(houseSchoolVO.getAddressId()) && houseSchoolVO.getSchoolId().equalsIgnoreCase(eduAddressSchool.getOrgId())) {
                                conFlag = true;
                            }
                        }
                        if (conFlag) {
                            continue;
                        }
                        //判断启用时间是否小于参数设置时间
                        HouseSchoolVO vo = Convert.convert(HouseSchoolVO.class, eduHouse);
                        vo.setOfflineFlag(BoolEnum.FALSE.getType());
                        vo.setServiceAreaFlag(eduAddressSchool.getServiceAreaFlag());
                        if(StringUtils.isBlank(vo.getServiceAreaFlag())){
                            vo.setServiceAreaFlag(BoolEnum.FALSE.getType());
                        }
                        if(StringUtils.isBlank(eduAddressSchool.getNativeFlag())){
                            vo.setNativeFlag(BoolEnum.FALSE.getType());
                        }else{
                            vo.setNativeFlag(eduAddressSchool.getNativeFlag());
                        }

                        boolean addFlag=true;
                        if(!BoolEnum.TRUE.getType().equals(eduAddressSchool.getHouseEndTimeNo())){
                            if(eduHouse.getRegisterDate()!=null){
                                Long djTime=eduHouse.getRegisterDate().getTime()/1000;
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                    //服务区
                                    if(eduAddressSchool.getHouseEndTimeFw()!=null){
                                        Long endTime=eduAddressSchool.getHouseEndTimeFw().getTime()/1000;
                                        if(djTime>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(djTime>houseEndTimeFw){
                                            addFlag=false;
                                        }
                                    }
                                }else{
                                    //正学区
                                    if(eduAddressSchool.getHouseEndTime()!=null){
                                        Long endTime=eduAddressSchool.getHouseEndTime().getTime()/1000;
                                        if(djTime>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(djTime>houseEndTime){
                                            addFlag=false;
                                        }
                                    }
                                }
                            }else{
                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }

                        }

                        if(addFlag) {
                            if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduAddressSchool.getVerificationFlag())){
                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }
                            if (AuthStatusEnum.NODO.getType().equalsIgnoreCase(eduHouse.getAuthStatus())){
                                //房产表示待审核的数据，需要上传核验材料
                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }
                            if (!CollectionUtils.isEmpty(tpschoolList)){
                                List<String> toSchoolIdList=new ArrayList<>();
                                for (BreakAreaVO tpSchool : tpschoolList) {
                                    if (tpSchool.getFromSchoolId().equals(eduAddressSchool.getOrgId())){
                                        toSchoolIdList.add(tpSchool.getToSchoolId());
                                    }
                                }
                                if (!CollectionUtils.isEmpty(toSchoolIdList)){
                                    if (eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                        vo.setCategoryFlag(true);
                                    }else{
                                        vo.setCategoryFlag(false);
                                    }
                                    vo.setToSchoolIdList(toSchoolIdList);
                                }else{
                                    if (!eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                        continue;
                                    }
                                    vo.setCategoryFlag(true);
                                }

                            }else{
                                if (!eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                    continue;
                                }
                                vo.setCategoryFlag(true);
                            }
                            vo.setSchoolId(eduAddressSchool.getOrgId());
                            vo.setAreaCode(eduAddressSchool.getAreaCode());
                            vo.setSchoolCategory(eduAddressSchool.getSchoolCategory());
                            vo.setSchoolName(eduAddressSchool.getSchoolName());
                            vo.setSchoolNature(eduAddressSchool.getSchoolNature());
                            vo.setShortName(eduAddressSchool.getShortName());
                            retList.add(vo);
                        }
                    }
                }
            }
        }

        return retList;
    }
    //获取户籍信息所属学校
    public List<HouseholdSchoolVO> getHouseholdSchool(EduStudentEnrollPreVO eduStudentEnrollPre,List<EduHousehold> list, Map<String, EduOperationCacheDetailVO> operation){

        List<HouseholdSchoolVO> retList=new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)){
            CommonVO tpVO = new CommonVO();
            tpVO.setParamKey("EDU_MZGXDXQ_TP");
            String schoolTPStr = commonIntegration.getValueByKey(tpVO);
            List<BreakAreaVO> tpschoolList=new ArrayList<>();
            if (StringUtils.isNotBlank(schoolTPStr)){
                tpschoolList= JSON.parseArray(schoolTPStr, BreakAreaVO.class);
            }
            // 户籍启用是参数
            EduOperationCacheDetailVO hjOperation=operation.get("YW025");
            Long householdEndTime=hjOperation.getEndTime().getTime()/1000;
            // 服务区房产启用是参数
            EduOperationCacheDetailVO hjfwOperation=operation.get("YW061");
            if (hjfwOperation.getEndTime() == null){
                throw new AppException("YW061未配置截至时间，请联系管理员进行配置");
            }
            Long householdEndTimeFw=hjfwOperation.getEndTime().getTime()/1000;
            for(EduHousehold eduHousehold:list){
                //获取地址和学校关联关系信息
                Boolean flag = true;
                String addressId=eduHousehold.getAddressId();
                String address= Convert.toDBC(eduHousehold.getAddress());
                if(StringUtils.isNotBlank(addressId)){
                    EduAddress eduAddress=eduAddressService.getById(addressId);
                    if(eduAddress==null){
                        flag=true;
                        addressId="";
                    }else {
                        if (!eduAddress.getAddressName().equals(address)) {
                            flag = true;
                            addressId = "";
                        } else {
                            flag = false;

                        }
                    }
                }
                if(flag){
                    QueryWrapper<EduAddress> eduAddressQueryWrapper=new QueryWrapper<>();
                    eduAddressQueryWrapper.lambda().eq(EduAddress::getAddressName,address);
                    List<EduAddress> addressList=eduAddressService.list(eduAddressQueryWrapper);
                    if(CollectionUtils.isEmpty(addressList)){
                        throw new AppException("地址池中未找到该户籍地址，请先联系管理员添加");
                    }else{
                        if(addressList.size()>1){
                            throw new AppException("同一户籍地址在地址池中找到多条数据，请联系管理员处理");
                        }
                        addressId=addressList.get(0).getAddressId();
                    }
                }
                SchoolDistrictQueryVO queryVO=new SchoolDistrictQueryVO();
                queryVO.setAddressId(addressId);
                //剔除学段，查询地址相关所有学校
                if (CollectionUtils.isEmpty(tpschoolList)) {
                    queryVO.setSchoolCategory(eduStudentEnrollPre.getSchoolCategory());
                }
                List<SchoolDistrictVO> schoolList= eduAddressSchoolService.getSchoolInfo(queryVO);

                if (!CollectionUtils.isEmpty(schoolList)){
                    for(SchoolDistrictVO eduAddressSchool:schoolList){
                        boolean conFlag = false;
                        for (HouseholdSchoolVO householdSchoolVO : retList) {
                            if (eduAddressSchool.getAddressId().equalsIgnoreCase(householdSchoolVO.getAddressId()) && householdSchoolVO.getSchoolId().equalsIgnoreCase(eduAddressSchool.getOrgId())) {
                                conFlag = true;
                            }
                        }
                        if (conFlag) {
                            continue;
                        }
                        //判断启用时间是否小于参数设置时间
                        boolean addFlag = true;
                        HouseholdSchoolVO vo= Convert.convert(HouseholdSchoolVO.class,eduHousehold);
                        vo.setOfflineFlag(BoolEnum.FALSE.getType());
                        vo.setServiceAreaFlag(eduAddressSchool.getServiceAreaFlag());
                        if(StringUtils.isBlank(vo.getServiceAreaFlag())){
                            vo.setServiceAreaFlag(BoolEnum.FALSE.getType());
                        }
                        if(StringUtils.isBlank(eduAddressSchool.getNativeFlag())){
                            vo.setNativeFlag(BoolEnum.FALSE.getType());
                        }else{
                            vo.setNativeFlag(eduAddressSchool.getNativeFlag());
                        }
                        if(!BoolEnum.TRUE.getType().equals(eduAddressSchool.getHouseholdEndTimeNo())){
                            if(StringUtils.isNotBlank(eduHousehold.getQysj())){
                                Long qysj= DateUtil.parse(eduHousehold.getQysj()).getTime()/1000;
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                    //服务区
                                    if(eduAddressSchool.getHouseholdEndTimeFw()!=null){
                                        Long endTime=eduAddressSchool.getHouseholdEndTimeFw().getTime()/1000;
                                        if(qysj>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(qysj>householdEndTimeFw){
                                            addFlag=false;
                                        }
                                    }
                                }else{
                                    //正学区
                                    if(eduAddressSchool.getHouseholdEndTime()!=null){
                                        Long endTime=eduAddressSchool.getHouseholdEndTime().getTime()/1000;
                                        if(qysj>endTime){
                                            addFlag=false;
                                        }
                                    }else{
                                        if(qysj>householdEndTime){
                                            addFlag=false;
                                        }
                                    }
                                }
                            }else{
                                if(eduHousehold.getUpdateTime()!=null){
                                    //更新时间在设置的截止时间之后的需要线下核验
                                    Long qysj= eduHousehold.getUpdateTime().getTime()/1000;
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceAreaFlag())){
                                        //服务区
                                        if(eduAddressSchool.getHouseholdEndTimeFw()!=null){
                                            Long endTime=eduAddressSchool.getHouseholdEndTimeFw().getTime()/1000;
                                            if(qysj>endTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }else{
                                            if(qysj>householdEndTimeFw){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }
                                    }else{
                                        //正学区
                                        if(eduAddressSchool.getHouseholdEndTime()!=null){
                                            Long endTime=eduAddressSchool.getHouseholdEndTime().getTime()/1000;
                                            if(qysj>endTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }else{
                                            if(qysj>householdEndTime){
                                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                            }
                                        }
                                    }
                                }else{
                                    vo.setOfflineFlag(BoolEnum.TRUE.getType());
                                }

                            }


                        }
                        if(addFlag){
                            if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduAddressSchool.getVerificationFlag())){
                                vo.setOfflineFlag(BoolEnum.TRUE.getType());
                            }
                            vo.setSchoolId(eduAddressSchool.getOrgId());
                            vo.setAreaCode(eduAddressSchool.getAreaCode());
                            vo.setSchoolCategory(eduAddressSchool.getSchoolCategory());
                            vo.setSchoolName(eduAddressSchool.getSchoolName());
                            vo.setSchoolNature(eduAddressSchool.getSchoolNature());
                            vo.setShortName(eduAddressSchool.getShortName());
                            if (!CollectionUtils.isEmpty(tpschoolList)){
                                List<String> toSchoolIdList=new ArrayList<>();
                                for (BreakAreaVO tpSchool : tpschoolList) {
                                    if (tpSchool.getFromSchoolId().equals(eduAddressSchool.getOrgId())){
                                        toSchoolIdList.add(tpSchool.getToSchoolId());
                                    }
                                }
                                if (!CollectionUtils.isEmpty(toSchoolIdList)){
                                    if (eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                        vo.setCategoryFlag(true);
                                    }else{
                                        vo.setCategoryFlag(false);
                                    }
                                    vo.setToSchoolIdList(toSchoolIdList);
                                }else{
                                    if (!eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                        continue;
                                    }
                                    vo.setCategoryFlag(true);
                                }

                            }else{
                                if (!eduStudentEnrollPre.getSchoolCategory().equals(eduAddressSchool.getSchoolCategory())){
                                    continue;
                                }
                                vo.setCategoryFlag(true);
                            }

                            retList.add(vo);
                        }

                    }
                }
                break;
            }
        }
        return  retList;
    }

    /**
     * 查询监护人信息
     *
     * @param enrollPre
     * @return
     */
    private void searchGuardians(EduStudentEnrollPreVO enrollPre) {
        String studentEnrollPreId = enrollPre.getStudentEnrollPreId();
        if (StringUtils.isNotBlank(studentEnrollPreId)) {
            QueryWrapper<EduStudentEnrollFamily> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnrollFamily::getStudentEnrollPreId, studentEnrollPreId);
            List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(queryWrapper);
            if(CollectionUtils.isEmpty(familyList)){
                List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
                EduStudentEnrollFamilyVO familyVOFather = new EduStudentEnrollFamilyVO();
                EduStudentEnrollFamilyVO familyVOMother = new EduStudentEnrollFamilyVO();
                if(!StringUtils.isBlank(enrollPre.getFatherIdcard())){
                    familyVOFather.setIdcard(enrollPre.getFatherIdcard());
                    familyVOFather.setFullName(enrollPre.getFatherName());
                    familyVOFather.setCardType(enrollPre.getFatherCardType());
                    familyVOFather.setWork(enrollPre.getFatherWork());
                    familyVOFather.setCellphone(enrollPre.getFatherCellphone());
                    familyVOFather.setRelationshipType("1");
                }
                if(!StringUtils.isBlank(enrollPre.getMotherIdcard())){
                    familyVOMother.setIdcard(enrollPre.getMotherIdcard());
                    familyVOMother.setFullName(enrollPre.getMotherName());
                    familyVOMother.setRelationshipType("2");
                    familyVOMother.setCardType(enrollPre.getMotherCardType());
                    familyVOMother.setWork(enrollPre.getMotherWork());
                    familyVOMother.setCellphone(enrollPre.getMotherCellphone());
                }
                guardians.add(familyVOFather);
                guardians.add(familyVOMother);
                enrollPre.setFamilyList(guardians);
            }else{
                searchGuardians(enrollPre,familyList);
            }
        }
    }
    private void searchGuardians(EduStudentEnrollPreVO enrollPre,List<EduStudentEnrollFamily> familyList) {
        List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
        if (!CollectionUtils.isEmpty(familyList)) {
            for (EduStudentEnrollFamily enrollFamily : familyList) {
                EduStudentEnrollFamilyVO familyVO=Convert.convert(EduStudentEnrollFamilyVO.class,enrollFamily);
                guardians.add(familyVO);
                if (RelationTypeEnum.father.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setFatherIdcard(enrollFamily.getIdcard());
                    enrollPre.setFatherName(enrollFamily.getFullName());
                    enrollPre.setFatherCardType(enrollFamily.getCardType());
                    enrollPre.setFatherWork(enrollFamily.getWork());
                    enrollPre.setFatherCellphone(enrollFamily.getCellphone());
                } else if (RelationTypeEnum.mother.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setMotherIdcard(enrollFamily.getIdcard());
                    enrollPre.setMotherName(enrollFamily.getFullName());
                    enrollPre.setMotherCardType(enrollFamily.getCardType());
                    enrollPre.setMotherWork(enrollFamily.getWork());
                    enrollPre.setMotherCellphone(enrollFamily.getCellphone());
                }else{
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(enrollFamily.getHouseFlag())){
                        enrollPre.setRelationshipType(enrollFamily.getRelationshipType());
                        enrollPre.setRelationshipName(enrollFamily.getFullName());
                        enrollPre.setRelationshipIdcard(enrollFamily.getIdcard());
                        enrollPre.setRelationshipCardType(enrollFamily.getCardType());
                        enrollPre.setWork(enrollFamily.getWork());
                        enrollPre.setCellphone(enrollFamily.getCellphone());
                    }

                }
            }
        }
        enrollPre.setFamilyList(guardians);
    }
    private EduStudentEnrollPreVO getPreById(EduStudentEnrollPreKeyVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            throw new AppException("预采集id不能为空");
        }
        //判断预采集表是否迁移
        EduStudentEnrollPreVO preVO = new EduStudentEnrollPreVO();
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_ENROLL_PRE));
        if (!queryHistoryFlag){
            EduStudentEnrollPre eduStudentEnrollPre =
                    eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());

            if (eduStudentEnrollPre == null) {
                throw new AppException("未找到预采集数据");
            }
            BeanUtil.copyProperties(eduStudentEnrollPre, preVO, CopyOptions.create().ignoreCase());
        }else {
            EduhStudentEnrollPre eduhStudentEnrollPre = eduhStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if (eduhStudentEnrollPre == null) {
                throw new AppException("未找到预采集数据");
            }
            //判断是否加密
            if ("1".equals(eduhStudentEnrollPre.getEncryptFlag())){
                eduStudentEnrollPreService.decrypt(eduhStudentEnrollPre);
            }
            BeanUtil.copyProperties(eduhStudentEnrollPre, preVO, CopyOptions.create().ignoreCase());
        }
        if (!AuthStatusEnum.YES.getType().equals(preVO.getAuthStatus())) {
            throw new AppException("该预采集未审核或者审核不通过");
        }
        if (StringUtils.isBlank(preVO.getCardType())) {
            preVO.setCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getMotherCardType())) {
            preVO.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getFatherCardType())) {
            preVO.setFatherCardType(CardTypeEnum.idcard.getType());
        }
        Boolean singleParentFlag=false;
        if(StringUtils.isBlank(preVO.getMotherIdcard())){
            singleParentFlag=true;
        }
        if(StringUtils.isBlank(preVO.getFatherIdcard())){
            singleParentFlag=true;
        }
        preVO.setSingleParentFlag(singleParentFlag);
        return preVO;
    }
    private Boolean checkEnroll(String idcard, Integer year) {
        EduOperationCacheDetailVO eduOperationCacheDetailVO=operationCacheIntegration.getPeriodYear();
        Integer thisYear=eduOperationCacheDetailVO.getYear();
        if (year == null) {
            year=thisYear;
        }
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getIdcard).eq(EduStudentEnroll::getIdcard, idcard)
                .eq(EduStudentEnroll::getYear, year)
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
        if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
            return false;
        }
        return true;
    }
    private Boolean checkMnEnroll(String idcard, Integer year) {
        EduOperationCacheDetailVO eduOperationCacheDetailVO=operationCacheIntegration.getPeriodYear();
        Integer thisYear=eduOperationCacheDetailVO.getYear();
        if (year == null) {
            year=thisYear;
        }
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        QueryWrapper<EduStudentEnrollImitate> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnrollImitate::getIdcard).eq(EduStudentEnrollImitate::getIdcard, idcard)
                .eq(EduStudentEnrollImitate::getYear, year)
                .in(EduStudentEnrollImitate::getEnrollStatus, enrollStatusList);
        if (eduStudentEnrollImitateService.count(enrollQueryWrapper) <= 0) {
            return false;
        }
        return true;
    }
}
